package com.qf.threaddemo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class ThreadPoolDemo {

    public static void main(String[] args) throws InterruptedException {

        // 如何创建线程池？
//        ThreadPoolExecutor pool = new ThreadPoolExecutor();
        ExecutorService pool = Executors.newFixedThreadPool(5);
        // 刚创建好的线程池对象中是不是有线程
        System.out.println(pool);
        // 如何给线程池提交任务
        for (int i=0;i<10000;i++) {
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    int a = 1+1;
//                    System.out.println(Thread.currentThread().getName()+":start task");
                }
            });
        }
        System.out.println(pool);
        Thread.sleep(10);
        System.out.println(pool);

        // 关闭线程池
        pool.shutdown();

    }

}
